package com.example.core.lock;

import org.jgroups.JChannel;
import org.jgroups.blocks.locking.LockService;

/****
 *
 */
public class LockImpl implements Lock {

    private LockService lockService;

    private JChannel channel;

    private String name;

    private java.util.concurrent.locks.Lock lock;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public LockImpl(JChannel channel, String name) {
        this.channel = channel;
        this.name = name;
        this.lockService = new LockService(this.channel);
        this.lock = this.lockService.getLock(this.name);
    }

    @Override
    public void lock() {
        this.lock.lock();
    }

    @Override
    public void unlock() {
        this.lock.unlock();
    }
}
